const baseurl='https://devapi.qweather.com/v7/weather/3d?key=3bb567bf215c40c4b140851f80bacdf5&location='//和风的实况的天气
const city='https://geoapi.qweather.com/v2/city/lookup?key=3bb567bf215c40c4b140851f80bacdf5&location='
Page({
  data:{
    loca:"",
    cityname:"",
    cityId:"",
    id:"",
  },
  onLoad(e){
    this.setData({
      loca:101010100
    })
    this.search();
  },
  input(e){
    console.log(e)//城市编码输入框
    this.setData({
      loca:e.detail.value
    })
  },
  search(){
    let loca=this.data.loca
    let url1=`${city}${loca}`
    //console.log(url)//显示查询天气的链接
    let that=this
    wx.request({
      url:url1,
      success(a){
        let cityId=a.data.location[0].id
        let cityname=a.data.location[0].name
        that.setData({
          cityId,
          cityname
        })
        that.aa()
      }
    })
  },
  aa(){
    var id=this.data.cityId
    var url=`${baseurl}${id}`
    console.log(url)
    var that=this
    wx.request({
      url,
      success(res){
        console.log(res)//链接返回的值
        var daily_forecast_today=res.data.daily[0];//今天的预报
        var daily_forecast_tomorrow=res.data.daily[1];//明天的预报
        var daily_forecast_afterTomor=res.data.daily[2];//后天的预报
        that.setData({
          today:daily_forecast_today,
          tomorrow:daily_forecast_tomorrow,
          afterTomor:daily_forecast_afterTomor,
        })
      }
    }) 
  }
})